package Xuanke;

public class Course {
    private String courseName;
    private int courseId;
    private float credit;
    private Teacher teacher;
    private String courseAddress;
    private Student[] students;
    //构造函数
    public Course(int courseId,String courseName,String courseAddress,float credit,Teacher teacher) {
        super();
        this.courseId = courseId;
        this.courseName = courseName;
        this.courseAddress = courseAddress;
        this.credit = credit;
        this.setTeacher(teacher);
        students = new Student[1];
    }
    public Course(int courseId,String courseName,String courseAddress,float credit) {
        super();
        this.courseId=courseId;
        this.courseName=courseName;
        this.courseAddress=courseAddress;
        this.credit=credit;
        students = new Student[1];
    }
    public Course(int courseId,String courseName,String courseAddress) {
        super();
        this.courseId=courseId;
        this.courseName=courseName;
        this.courseAddress=courseAddress;
        students = new Student[1];
    }
    public Course(int courseId,String courseName) {
        super();
        this.courseId=courseId;
        this.courseName=courseName;
        students = new Student[1];
    }

    public Course() {    //默认形式，要有以防万一
        super();
        students = new Student[1];
    }

    //修改或获取属性值id，name，credit，
    public void setId(int id){
        this.courseId=id;
    }
    public int getId(){
        return this.courseId;
    }
    public void setName(String name){
        this.courseName=name;
    }
    public String getName(){
        return this.courseName;
    }
    public void setCredit(float credit ){
        this.credit=credit;
    }
    public float getCredit(){
        return this.credit;
    }
    public Teacher getTeacher() {
        return teacher;
    }
    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }
    public void setcourseAddress(String courseAddress) {
        this.courseAddress = courseAddress;
    }

    //课加入学生
    public boolean addStudent(Student stu){
        boolean flag = false;//标志值：是否加入成功
        //if(!isSelectedStudent(stu)&&isNullStudent(stu)){
        for(int i=0;i<students.length;i++){
            if(students[i]==null){
                students[i]=stu;
                flag=true;
                break;
            }
        }
        return flag;
    }
    //课移除学生
    public boolean removeStudent(Student stu){
        boolean flag = false;
        //if(isSelectedStudent(stu)){//选过这门课
        for(int i=0;i<students.length;i++){
            if(students[i] == stu){
                students[i] = null;
                flag = true;
                break;
            }
        }
        return flag;
    }
    //显示选择课程的学生：
    public void displayStudent(){
        System.out.println("选择的课程："+this.courseName+"的学生有:");
        for(Student s:students){
            if(s!=null){
                System.out.print(s.getStudentName()+" ");
            }
        }
        System.out.println();
    }

}
